package xju_3_4.springboot_3_4.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import xju_3_4.springboot_3_4.entity.Friend;

import java.util.List;

@RestController
public class UserController {

    @Value("${friend.username}")
    private String userName;
    @Value("${friend.age}")
    private String age;

    @Value("${pets[0]}")
    private List<String> pets;

    @Autowired
    private Environment environment;

    @Autowired
    private Friend friend;

    @GetMapping("/test")
    public String test(@RequestParam(required = false, defaultValue = "hello") String name) {
        System.out.println(userName);
        System.out.println(age);
        System.out.println(pets);

        System.out.println("---------");
        System.out.println(environment.getProperty("friend.username"));
        System.out.println(environment.getProperty("friend.age"));
        System.out.println(environment.getProperty("pets[0]"));
        System.out.println(friend);
        return "test" + name;
    }
}
